package com.tasklist.util;

import org.hibernate.Session;
import org.hibernate.Transaction;

public class Conecta {
	private Session sessao;
	private Transaction transacao;
	
	public void abreConexao() {
		this.sessao = HibernateUtil.getSession().getCurrentSession();
		this.transacao = sessao.beginTransaction();
	}

	public void fechaConexao() {
		this.transacao.commit();
		
		try {
			if(this.sessao.isOpen()){
				this.sessao.close();
			}
		} catch (Exception e) {
			System.out.println("Deu problema no fechamento da conexao" + e.getMessage());
		}
	}
	
	public static void main(String[] args) {
		Conecta c = new Conecta();
		c.abreConexao();
		c.fechaConexao();
	}
}
